<script type="text/javascript" language="javascript" charset="utf-8">
$(".menu-wrap li").removeClass("active-link");
$(".menu-wrap #goods").addClass("active");
$("#goods #info").addClass("active-link");
$("#goods #good_list a").addClass("active-link");
</script>
<div class="mask">
</div>

<div class="common-tit">
  <h2>商品详情</h2>
  <span>商品管理 > 商品详情</span>
  <div class="cours-gbtn">
    <%#<a id="sale" href="javacript:;">售卖</a>%>
    <%=link_to '售卖', new_admin_order_path(good_id: @good.id), remote: true, id: "sale" %>
    <% if @good.status == '下架' %>
      <%=link_to '上架', change_status_admin_good_path(@good), data: {confirm: '确定要下架吗？'} %>
    <% else %>
      <%=link_to '下架', change_status_admin_good_path(@good), data: {confirm: '确定要下架吗？'} %>
    <% end %>
    <%=link_to '编辑', edit_admin_good_path(@good) %>
  </div>
</div>
<div class="course-box">
  <h3>
    <span>基本信息</span>
  </h3>

  <% if @good.good_type == '课程商品' %>
    <div class="commo-dec clearfix">
      <div class="camera">
        <% if @good.avatar.present? %>
          <%= image_tag("#{@good.avatar_url}", size: "150x150", alt: "头像" ,id: "good_avatar_img")%>
        <% else %>
          <%= image_tag("/avatar.png", size: "150x150", alt: "头像" ,id: "good_avatar_img")%>   
        <% end %> 
      </div>
      <ul>
        <li>
          <span>商品分类:</span>
          <em id="comsh"><%= @good.good_type %></em>
        </li>
        <li>
          <span>商品类型:</span>
          <em><%= @good.good_info %></em>
        </li>
        <li>
          <span>商品名称:</span>
          <em><%= @good.name %></em>
        </li>
        <li>
          <span>课程规格:</span>
          <em><%= @good.amount %><%= @good.course_unit %></em>
        </li>
        <li>
          <span>商品价格:</span>
          <em><%= @good.price %></em>
        </li>
        <li>
          <span>商品库存:</span>
          <em>
            <% if @good.stock.present? %>
              <%= @good.stock %>
            <% else %>
              -
            <% end %>
          </em>
        </li>
        <li>
          <span>有效期:</span>
          <em><%= @good.month_of_validity %>月</em>
        </li>
      </ul>
    </div>
  <% elsif @good.good_type == '周边商品' %>
    <div class="commo-dec clearfix">
      <div class="camera">
        <% if @good.avatar.present? %>
          <%= image_tag("#{@good.avatar_url}", size: "150x150", alt: "头像" ,id: "good_avatar_img")%>
        <% else %>
          <%= image_tag("/avatar.png", size: "150x150", alt: "头像" ,id: "good_avatar_img")%>   
        <% end %> 
      </div>
      <ul>
        <li>
          <span>商品分类:</span>
          <em id="comsh"><%= @good.good_type %></em>
        </li>
        <li>
          <span>商品类型:</span>
          <em><%= @good.good_info %></em>
        </li>
        <li>
          <span>商品名称:</span>
          <em><%= @good.name %></em>
        </li>
        <li>
          <span>商品库存:</span>
          <em>
            <% if @good.stock %>
              <%= @good.stock %>
            <% else %>
              -
            <% end %>
          </em>
        </li>
        <li>
          <span>商品价格:</span>
          <em><%= @good.price %></em>
        </li>
        <li class="st-al">
          <span>简介:</span>
          <em>
            <% if @good.remark %>
              <%= @good.remark %>
            <% else %>
              -
            <% end %>
          </em>
        </li>
      </ul>
    </div>
  <% end %>
  <h3>
    <span>相关信息</span>
  </h3>
  <div class="course-b clearfix">
    <div class="relevant clearfix">
      <div>
        <span>销量:</span>
        <em><%= @good.sale_amount %></em>
      </div>
      <div>
        <span>状态:</span>
        <em><%= @good.good_status %></em>
      </div>
    </div>
  </div>
  <% if @discounts.present? %>
    <h3>
      <span>折扣优惠</span>
    </h3>
    <div class="course-b clearfix">
      <div class="co-discount clearfix">
        <% if @num_discounts.present? %>
          <div class="showdis">
            <span>数量:</span>
          </div>
          <div class="showdis-con">
            <% @num_discounts.each do |num| %>
             <div>
              <span>超过</span>
              <em><%= num.amount %></em>
              <b>件</b>
              <strong>折扣为:</strong>
              <em><%= num.percent %></em>
              <b>%</b>
            </div>
            <% end %>
          </div>
        <% end %>
        <% if @time_discounts.present? %>
          <div class="showdis">
            <span>时间:</span>
          </div>
          <div class="showdis-con">
            <% @time_discounts.each do |time| %>
              <div>
              <em><%= time.begin_at.strftime("%Y年%m月%d日") %></em>
              <i>-</i>
              <em><%= time.end_at.strftime("%Y年%m月%d日") %></em>
              <strong>折扣为:</strong>
              <em><%= time.percent %></em>
              <b>%</b>
              </div>
            <% end %>
          </div>
        <% end %>

      </div>
    </div>
  <% end %>
</div>
</div>
<script src="/assets/js/common.js"></script>
<script>
if ($("#comsh").text() == "课程商品") {
  $(".c-nost").css({
    "display" : "none"
  })
};
$(".purch-num").change(function() {
  console.log($(this).val());
  var unit = $(this).val();
    $.ajax({
      type:'get', url:"/admin/goods/" + <%= @good.id %> + "/price?unit=" + unit,
      success: function(data) {
        if (data.error) {
        }
      }
    });
})
// 控制radio按钮
$(".purch-b .ra-btn").on("click", function() {
  $(this).prev().attr("checked", "checked");
})
// 可放 common.js
$(".mask .ra-btn").on("click", function() {
  $(".mask .ra-btn").removeClass("ra-checked");
  $(this).addClass("ra-checked");
  $(this).prev("input").prop("checked", true);
  if ($(this).hasClass("no-st")) {
    $("#cho-stud").css({
      "display" : "none"
    });
  } else {
    $("#cho-stud").css({
      "display" : "block"
    });
    if ($(this).hasClass("dis-s")) {
      $("#cho-stud .intention").css({
        "display" : "none"
      });
      $("#cho-stud .n-intention").css({
        "display" : "block"
      });
    } else {
      $("#cho-stud .intention").css({
        "display" : "block"
      });
      $("#cho-stud .n-intention").css({
        "display" : "none"
      });
    }
  }
});
$("#sale").on("click", function() {
  $(".mask").css({
    "display" : "block"
  });
  $(".mask-box").css({
    "margin-top" : -($(".mask-box").height() + parseInt($(".mask-box").css("padding-bottom")))/2
  })
})
// 弹窗(有重复则删除)
$(".mask-head span").on("click", function() {
  $(this).parent().parent().find("input").val("");
  $(".mask").css({
    "display" : "none"
  })
})
$(".mask-confirm").on("click", function() {
  $(".mask").css({
    "display" : "none"
  })
})
/* 单选下拉列表 */
$(".purch-b .single-downbtn").on("click", function() {
  if ($(this).next(".single-dropdown").hasClass("menuopen")) {
    $(this).next(".single-dropdown").removeClass("menuopen");
  } else {
    $(this).next(".single-dropdown").addClass("menuopen");
    $(this).parent().hover(function() {

    }, function() {
      $(this).children(".single-dropdown").removeClass("menuopen");
    });
    $(".purch-b .menuopen li").on("click", function() {
      $(this).parent().parent().removeClass("menuopen");
      $(this).parent().parent().parent().find("span").text($(this).text());
      $(this).parent().parent().find("input").val("");
      $(".purch-b .single-dropdown li").removeClass("mul-hide");
      $("#choStu").val($(this).attr("data_id"));
    });
    $(this).next("div").find("input").on('input',function(){
      console.log($(this));
      if ($(this).val() != "") {
          console.log($(this).val());
          $(".purch-b .single-dropdown li").addClass("mul-hide");
          console.log($($(".single-dropdown li:contains(" + $(this).val() + ")")).removeClass("mul-hide"));
      } else {
        $(".purch-b .single-dropdown li").removeClass("mul-hide");
      }
    })
  }
});
</script>
